#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Author  :   JingV
@Version :   1.0
@Contact :   None
@License :   None
@Desc    :   None
'''


class Solution(object):
    def lengthOfLastWord(self, s):
        result = 0
        for i in range(len(s)-1, -1, -1):
            if s[i] == " ":
                if result == 0:
                    continue
                return result
            else:
                result += 1
        return result


def main():
    solution = Solution()
    tests = ['hello world', 'world', 'a', '']
    for s in tests:
        print(solution.lengthOfLastWord(s))


if __name__ == "__main__":
    main()
